home *** CD-ROM | disk | FTP | other *** search
/ C & C++ Multimedia Cyber Classroom / C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso / src / fig04_08.jar / Ch04 / Fig04_08 / Fig04_08.cpp
C/C++ Source or Header  |  1997-10-13  |  426b  |  20 lines

  1. // Fig. 4.8: fig04_08.cppf
  2. // Compute the sum of the elements of the array
  3. #include <iostream.h>
  4.  
  5. int main()
  6. {
  7.    const int arraySize = 12;
  8.    int a[ arraySize ] = { 1, 3, 5, 4, 7, 2, 99, 
  9.                           16, 45, 67, 89, 45 };
  10.    int total = 0;
  11.  
  12.    for ( int i = 0; i < arraySize ; i++ )
  13.       total += a[ i ];
  14.    
  15.    cout << "Total of array element values is " << total << endl;
  16.    return 0;
  17. }
  18.  
  19.  
  20.